SWEP.Author = "Brwarner";
SWEP.Contact = "";
SWEP.Purpose = "Blows things up";
SWEP.Instructions = "Left-Click: Place a bomb";

SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;

SWEP.ViewModel = "models/weapons/v_slam.mdl";
SWEP.WorldModel = "models/weapons/w_slam.mdl";

SWEP.Primary.ClipSize = 1;
SWEP.Primary.DefaultClip = 1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "bombs";

SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = "none";

function SWEP:Deploy()
	self.Weapon:SendWeaponAnim(ACT_SLAM_TRIPMINE_IDLE);
end

function SWEP:Initialize()
end

//Left-Click action
function SWEP:PrimaryAttack()
	//Check if we have ammo
	if(self.Weapon:Clip1() <= 0) then return; end
	
	//See if we are close to any entities
	local tr = self.Owner:GetEyeTrace();
	
	local ent = tr.Entity;
	local length = (tr.HitPos - tr.StartPos):Length();
	if(ent && ent:IsValid() && ent:GetClass() == "bh_block" && length < 50 && ent:GetTeam() != self.Weapon.Owner:Team()) then
		//Play the correct animation
		self.Weapon:SendWeaponAnim(ACT_SLAM_TRIPMINE_ATTACH);
		//Dispense a clip
		self.Weapon:SetClip1(self.Weapon:Clip1()-1);
		
		//Create our entity
		local bomb = ents.Create("bh_bomb");
		bomb:SetPos(tr.HitPos);
		bomb:SetOwner(self.Weapon.Owner);
		bomb:Spawn();
		constraint.Weld(ent, bomb, tr.PhysicsBone, 0, 0);
	end
end

function SWEP:Think()
	if(self.Weapon:Clip1() <= 0) then self.Weapon:SendWeaponAnim(ACT_SLAM_DETONATOR_IDLE);
	else self.Weapon:SendWeaponAnim(ACT_SLAM_TRIPMINE_IDLE); end
end